package com.bz.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 解决跨域访问
 *
 * @author wgb
 * @date 2019/12/29 22:01
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    /**
     * 不需要登录拦截的url
     */

    final String[] authInterceptPaths = {
            //目录
            "/static/**",
            "/druid/**",
            //单链接
            "/403",
            "/404",
            "/error",
            "/login",
            "/index",
            //swagger
            "/v2/**",
            "/webjars/**",
            "/swagger-resources/**",
            "/swagger-ui.html",
            //"*.html*",
    };


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
              .allowedOrigins(authInterceptPaths)
              .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
              .maxAge(3600)
              .allowCredentials(true);
    }

    @Bean
    public StandardServletMultipartResolver multipartResolver() {
        return new StandardServletMultipartResolver();
    }
}

